<template>
    <div class="r_main">
        <div class="tabIn">
            <div class="tab">
                通知私信
            </div>

        </div>
        <div class="form_con">
            <div class="outer">
                <div class="list">
                    <div class="main" v-for="(item, index) in list" :key="index">
                        <div class="top">
                            <span>留言账号：{{ item.uname }}</span>
                            <span>留言时间：{{ item.time }}</span>
                        </div>
                        <p v-html="item.content">
                        </p>
                        <div class="bombtn">
                            <div @click="confirm(item.id)" class="icon">
                                <i class="iconfont">&#xe7ea;</i>
                                <span>删除</span>
                            </div>

                            <div class="icon" @click="openPop(item.id)" v-if="item.is_admin != 1">
                                <i class="iconfont">&#xe63a;</i>
                                <span>回复</span>
                            </div>
                        </div>
                    </div>
                    <el-empty description="没有内容了" v-if="list.length == 0"></el-empty>

                </div>
            </div>
        </div>
        <el-dialog :visible.sync="dialogVisible" :width="$store.getters.isMobile ? '90%' : '700px'">
            <span slot="title" class="dialog-header">
                <i style="color:#d41f19;margin-right: 12px;" class="iconfont">&#xe63a;</i>私信回复
            </span>
            <el-form ref="form" label-width="6.25vw">

                <div class="select">
                    <el-form-item label="回复内容:" required>
                        <el-input type="textarea" v-model="remark" placeholder="请输入回复内容"></el-input>
                    </el-form-item>
                </div>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="onsubmit">确 定</el-button>
            </span>
        </el-dialog>
    </div>

</template>
<script>
export default {
    data() {
        return {
            list: [],
            dialogVisible: false,
            totalPage: 1,
            pageNum: 1,
            loading: false,
            id: 0,
            remark: ''
        }
    },
    computed: {
        path() {
            return this.$route.path
        }
    },
    mounted() {
        this.getList()
        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },

    methods: {
        getList() {
            this.loading = true
            this.$api.getMsgs().then(res => {
                if (res.data.code == 1) {
                    this.totalPage = res.data.data.last_page
                    this.list = this.list.concat(res.data.data.data);
                    this.loading = false
                }

            })
        },
        confirm(id) {
            this.$confirm('确定删除该内容吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    id
                }
                this.$api.delMsg(params).then(res => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: res.data.msg,
                            type: 'success'
                        })
                        this.pageNum = 1
                        this.list = []
                        this.getList()

                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });

        },
        load() {
            console.log("处理触底");
            var page = this.pageNum

            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getList()

        },
        openPop(id) {
            this.id = id
            this.dialogVisible = true
        },
        onsubmit() {
            console.log(this.form);
            let params = {
                id: this.id,
                content: this.remark
            }
            this.$api.replyMsg(params).then(res => {
                if (res.data.code == 1) {
                    this.$message({
                        message: res.data.msg,
                        type: 'success'
                    })
                    this.remark = ''
                    this.dialogVisible = false

                }
            })
        },
        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                this.load()
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.r_main {
    width: 100%;

    .user {
        width: 100%;
        height: 200px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        padding: 0 30px;
        overflow: hidden;
        background: linear-gradient(to right, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));

        .bgg {
            position: absolute;
            width: 100%;
            height: auto;
            z-index: -1;

        }

        .left {
            display: flex;
            color: #fff;
            align-items: center;

            .avatar {
                width: 150px;
                height: 150px;
                margin-right: 27px;
                flex-shrink: 0;
                border-radius: 50%;
                overflow: hidden;

                img {
                    object-fit: cover;
                    width: 100%;
                    height: 100%;
                }
            }

            .info {
                .nane {
                    font-weight: bold;
                    font-size: 30px;
                    color: #FFFFFF;
                    margin-bottom: 13px;
                }

                .data {
                    display: flex;
                    align-items: center;
                    margin-bottom: 13px;

                    .line {
                        height: 18px;
                        display: block;
                        width: 2px;
                        background-color: #fff;
                        margin: 0 18px;
                    }

                    >div {
                        font-weight: 400;
                        font-size: 18px;
                        color: #999999;

                        >span {
                            color: #FFFFFF;
                        }
                    }
                }

                .address {
                    display: flex;
                    align-items: center;
                    margin-bottom: 10px;
                    font-weight: 400;
                    font-size: 16px;
                    color: #999999;

                    .line {
                        margin: 0 18px;
                        display: block;
                        height: 16px;
                        width: 2px;
                        background-color: #999;
                    }
                }

                .sign {
                    font-weight: 400;
                    font-size: 16px;
                    color: #FFFFFF;
                }
            }
        }

        .right {
            height: 100%;
            padding: 28px 0 38px;
            font-weight: 400;
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            flex-direction: column;
            font-size: 20px;
            color: #FFFFFF;

            .share {
                cursor: pointer;
                display: flex;
                align-items: center;
                justify-content: center;

                img {
                    width: 28px;
                    height: auto;
                    margin-left: 11px;
                }
            }

            .btn {
                display: flex;
                align-items: center;
                justify-content: center;

                button {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    width: 120px;
                    height: 48px;
                    background: #F98951;
                    border-radius: 24px;
                    opacity: 0.9;
                    margin-left: 26px;
                    font-weight: 400;
                    font-size: 20px;
                    color: #FFFFFF;
                    border: none;

                    &:nth-child(2) {
                        background: #1068E7;
                    }
                }
            }
        }
    }

    .tabIn {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        padding: 23px 0;
        background-color: #E5E5E5;
        position: sticky;
        top: 98px;
        z-index: 99;
        padding-left: 23px;
height: 60px;
        // border-top: 0.05rem solid #E8E8E8;
        .tab {
            font-weight: bold;
            font-size: 24px;
            color: #1068E7;
        }

    }

    .form_con {
        min-height: 500px;
        // overflow-y: auto;
    }
}

.outer {
    margin-top: 30px;
    padding-bottom: 20px;

    .list {
        .main {
            margin-top: 40px;
            padding: 0 22px 26px;
            border-bottom: 1px solid #99CCFF;
            font-weight: 400;
            font-size: 18px;
            color: #333333;

            .top {
                display: flex;
                align-items: center;

                span {
                    margin-right: 80px;
                }
            }

            >p {
                margin: 28px 0 35px;
            }
        }

        .bombtn {
            display: flex;
            justify-content: flex-end;
            align-items: center;

            .icon {
                display: flex;
                align-items: center;
                margin-left: 50px;
                font-weight: 400;
                font-size: 18px;
                color: #333333;
                cursor: pointer;

                i {
                    font-size: 20px;
                    color: #333333;
                    margin-right: 7px;
                }
            }
        }
    }
}

.dialog-header {
    font-weight: bold;
    font-size: 22px;
}

.dialog-footer {
    font-weight: bold;
    font-size: 22px;
    display: flex;
    justify-content: center;
    align-items: center;

    button {
        margin: 0 50px;
        width: 140px;
        height: 50px;
        font-size: 16px;
        line-height: 50px;
        padding: 0;
    }
}

@media screen and (max-width:768px) {

    .r_main .tabIn {
        height: 40px;
        padding: 0 20px;

        .tab {
            font-size: 15px;
        }

        .btn2 {
            font-size: 12px;
            width: 60px;
            height: 20px;
            line-height: 20px;
        }
    }

    .outer .list {
        padding: 0 10px;

        .main {
            margin-bottom: 15px;
            font-size: 14px;

            .top {
                font-weight: bold;
                justify-content: space-between;
                margin-bottom: 10px;
            }
        }

        .bombtn {
            .icon {
                font-size: 13px;
                margin-right: 10px;

                i {
                    font-size: 14px;
                    margin-right: 5px;
                }
            }
        }
    }
}
</style>